//
//  BaseModel.m
//  UI23_基类
//
//  Created by dllo on 16/1/14.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "BaseModel.h"

@implementation BaseModel


- (instancetype)initWithDic:(NSDictionary *)dic {
    self = [super init];
    if (self) {
        // 在初始化的过程中直接用字典 KVC给model赋值
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}

+ (instancetype)modelWithDic:(NSDictionary *)dic {
    // [self class] 本类对象, 子类执行父类方法时，[self class] 代表子类
    return [[[self class] alloc] initWithDic:dic];
}

+ (NSMutableArray *)modelHandleWithArray:(NSArray *)array {
    // 创建model数组
    NSMutableArray *arrModle = [NSMutableArray array];
    // 遍历字典
    for (NSDictionary *dic in array) {
        // 用字典创建和赋值本类model对象
        id model = [[self class] modelWithDic:dic];
        // 添加到数组中
        [arrModle addObject:model];
    }
    // 返回可变数组
    return arrModle;
}


- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}

- (id)valueForUndefinedKey:(NSString *)key {
    return nil;
}

@end
